"""
URL configuration for deom01django project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.shortcuts import HttpResponse
from book import views
from django.urls import reverse
def index(request):
    # url反转
    # print(reverse("book_detail_query_string"))
    # /book/str/1
    # print(reverse("book_str", kwargs={"book_id":1}))
    # /book?id=1:如果查询字符串的方式传参，那么就只能通过字符串拼接的方式
    # print(reverse("book_detail_query_string")+"?id=1")
    # 存在命名空间要加上命名空间/movie/list
    print(reverse("movie:movie_list"))
    return HttpResponse("hello world")

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', index, name='index'),

    #path('s', index), #http://127.0.0.1:8000/s
    #path('', index), #http://127.0.0.1:8000
    # http://127.0.0.1:8000/book?id=1
    # 有括号代表调用函数，没括号代表回调函数
    path('book/', views.book_detail_query_string, name="book_detail_query_string"),
    # http://127.0.0.1:8000/book?id=1
    # 在book_id前指定参数类型有两点好处
    # 1. 以后在浏览器中，如果book_id不是整数，会报错
    # 2. 以后在浏览器中，如果book_id就是整形，否则，默认是str类型
    # 可以加整形
    path('book/<int:book_id>', views.book_detail_path),
    # 可以加字符串
    path('book/str/<str:book_id>', views.book_str,name="book_str"),
    # 可以加下划线
    path('book/slug/<slug:book_id>', views.book_slug, name="book_slug"),
    # 可以加斜杠
    path('book/path/<path:book_id>', views.book_path, name="book_path"),
    # 导入模块
    path('movie/', include('movie.urls')),
    # 模仿实践测试
    path('music/', include('music.urls')),
]
